<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css"> 
    <script>
	    $(function(){
		    $('.squareL').on('click', function() {
	            var lastCon = $('.square ol li:last-child').detach();
	            $('.square ol').prepend(lastCon)
	            $('.square ol li:last-child').addClass('active')
	            $('.square ol li:last-child').siblings().removeClass('active')
	        })
	
	        $('.squareR').on('click', function() {
	            var lastCon = $('.square ol li:first-child').detach();
	            $('.square ol').append(lastCon)
	            $('.square ol li:last-child').addClass('active')
	            $('.square ol li:last-child').siblings().removeClass('active')
	        })
	    });
	    //生成文件数据集 
	    function makeFileList() {
			// 图片路径和名称
			var fileList = $("#nameImage").val().split("|/");
			var ftpFile = $("#ftpFile").val();
			var len = fileList.length;
			var pathHidden = '';
			var fileNamePathHidden = '';
			var ftpFileHidden = '';
			var moduleKbnHidden = '';
			var ftpKbnHidden='';
			// 生成路径
			for (var i = 1; i < len; i++) {
				var fileTemp = fileList[i].split("/");
				var urlTemp = '';
				var lenTemp = fileTemp.length;
				var nameTemp=fileTemp[lenTemp-1];
				if (fileList[i]!='') {
					for (var j = 0; j < (lenTemp-1); j++) {
						 urlTemp += fileTemp[j]+"/";
					}
					pathHidden +='<input type ="hidden" name ="uploadFileEntity.uploadFileList['+(i-1)+'].filePath" value = "/'+urlTemp+'"/>';
					fileNamePathHidden+='<input type ="hidden" name ="uploadFileEntity.uploadFileList['+(i-1)+'].uploadFile" value = "'+nameTemp+'"/>';
					ftpFileHidden+='<input type ="hidden" name ="uploadFileEntity.uploadFileList['+(i-1)+'].ftpFile" value = "'+ftpFile+'"/>';
					ftpKbnHidden+='<input type ="hidden" name ="uploadFileEntity.uploadFileList['+(i-1)+'].fileKbn" value = "0"/>';
					moduleKbnHidden+='<input type ="hidden" name ="uploadFileEntity.uploadFileList['+(i-1)+'].moduleKbn" value = "2"/>';
				}
			}
			$("#fileListHidden").html(pathHidden+fileNamePathHidden+ftpFileHidden+moduleKbnHidden+ftpKbnHidden);
		}
	    
	    //保存图片 
	    function saveFile(){
	    	makeFileList();
	    	var id = $("#id").val();
	    	var sourceKbn = $("#sourceKbn").val();
	    	//
	    	if (sourceKbn == "") {
	    		tipParent("无数据来源");
	    		return;
	    	//样品生产 
			}else if (sourceKbn == "specimenProduction") {
				var params = $("#inputForm").serialize();
				$.post("${ctx}/specimen/production/saveFile",params,function(result) {
					if (result == "true") {
						tipParent("图片保存成功");
						window.parent.frames[0].searchListForm();
						window.parent.frames[window.parent.frames.length-2].closeWin();
						closeWin();
					}else{
						tipParent("保存失败");
						return;
					}
				}, 'json');
			}
	    }
	    
	</script>
    </head>
	<body>
	<form id="inputForm">
	<input type="hidden" id="id" name="id" value="${id }"/>
	<input type="hidden" id="ftpFile" value="${ftpFile }"/>
	<input type="hidden" id="sourceKbn" value="${sourceKbn }"/>
	<div class="layerHeader clearfix">
		<p class="headerTitle">图片上传</p>
	    <div class="headerButton clearfix">
	    	<button type="button" onclick="saveFile()">上传图片</button>
	        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
	<div id = "fileListHidden"></div>
	<div class="tabBoxSm showHtml">
    	<div class="tabSm smOrderBox">
	        <div class="items clearfix">
	        	<div class="styleImgBg clearfix" style="width: 500px; height: 300px; padding-top: 30px; margin-left: 0px; float: left;">
					<div class="squareBtn squareL" style="margin-left: -5px;margin-top:-57px">
						<img src="${ctxStatic}/images/btn_left.png">
					</div>
					<div class="square" style="width: 330px; height: 230px; margin-top: -1px; margin-left: 20px;">
						<input type="hidden" id="nameImage" name="myStyleFile" value="${myStyleFileTemp}" htmlEscape="false" class="input-xlarge" />
						<sys:ckfinder input="nameImage" type="images"  uploadPath="/bigcargoStyle" selectMultiple="true" maxWidth="255" maxHeight="155" />
					</div>
					<div class="squareBtn squareR" style="margin-top:-287px;margin-left:370px">
						<img src="${ctxStatic}/images/btn_right.png">
					</div>
				</div>
	        </div> 
		</div>
    </div>
    </form>
</body>
</html>